<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport"
          content="width=device-width,user-scalable=no, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <title>选择服务套餐</title>
    <%- include('./_global/baseLibs') %>
    <link rel="stylesheet"  href="/static/css/mycontract.css" />
    <style>
        html, body {
            background: #fff;
        }

        .fwtc-choose-box {
            background: #fff;
            width: 1.45rem;
            height: 1.45rem;
            border: 1px solid #a19e9a;
        }
        .fwtc-choose-box:checked{
            background: url("/static/images/yes-blue.png") no-repeat 15%;
            background-size: contain;
        }
    </style>
</head>

<body>
<section class="page-wrap choose-service">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="title">选择服务套餐</div>
        </div>
    </header>
    <div class="fwtc-out-box">
        <div class="fwtc-box">
            <ul id="fwtc"></ul>
        </div>
    </div>
    <div class="tj-btn-box">
        <a id="qd-btn">确定</a>
    </div>
</section>
</body>
<!--

 -->
<script type="text/html" id="tcLi">
    <li>
        <label class="title-span">
            <span class="text-blue-left" name="fwbmc"></span>
            <!--<span class="text-blue-right">价格：<span class="text-blue-right" name="JG"></span></span>-->
        </label>
        <div class="fwnrContainer"></div>
        <span><span>签约周期：</span><span class="blue-num" name="QYZQ"></span><span name="QYZQDW"></span></span>
        <input type="checkbox" name="tc" class="fwtc-choose-box">
    </li>
</script>
<script type="text/javascript">

    function checkForbid(i){
        i = JSON.parse(i);
        var list=$(".fwtc-box").find(".fwtc-choose-box");
        $(list).each(function(index,arr){
            if(index!=i){
                arr.checked=false;
            }else{
                arr.checked=true;
            }

        });

    }


    var page_xzfwtc = (function($, page_xzfwtc) {


        function initView() {
            /**确定选择服务套餐*/
            $("#qd-btn").on("click", function () {
                if (page_xzfwtc.validate()) {
                    var selectedTcxxs = [];
                    $("input:checkbox[name='tc']:checked").each(function () {
                        var tcxx = $(this).parents("li").data();
                        var selectedTcxx = $.extend({}, tcxx);
                        delete selectedTcxx["children"];
                        selectedTcxxs.push(selectedTcxx);
                    })
                    StoreCache.setCache("QYFW_SELECTED_TCXX", selectedTcxxs);
                    $.pageSwitch.goToUrl("mySignService","yqyqr");
                }
                else {
                    $.QuickAlert.alertFail({content: "请勾选套餐信息"});
                }
            });
        }

        /**验证信息*/
        function validate() {
            var checkeds = $("input:checkbox[name='tc']:checked");
            if (checkeds.length > 0) {
                return true;
            }
            else {
                return false;
            }
        }

        function initData() {
            /**获取团队信息*/
            var tdxx = StoreCache.getCache("QYFW_TDXX");
            $("body").data("tdxx", tdxx);
            page_xzfwtc.queryTcxx();

        }

        /**查询团队套餐信息*/
        function queryTcxx() {
            $("#fwtc").empty();
            var tdxx = $("body").data("tdxx");
            console.log(tdxx);
            var yydm = tdxx["yljgid"];
            // var xzqh = tdxx["xzqhdm"];
            var xzqh = $.QuickUrlUtils.getRequest('xzqhdm');
            $.QuickRemote.AjaxJson({
                funcName:"/api/gzd/qyfw/queryFwbAndFwxxListToJkcs"
                ,callback: page_xzfwtc.queryTcxxHandler
                ,params:{ yljgid: yydm,jgxzqhdm: xzqh}
            });
        }

        function queryTcxxHandler(result) {
            var container = $("#fwtc");
            if (result) {
                for (var i in result) {
                    var item = result[i];
                    var li = page_xzfwtc.setItemInfo(item,i);
                    container.append(li);
                }
            }
        }

        function setItemInfo(item,i) {
            var li = $($("#tcLi").html());
            item.QYZQ = "1";
            item.QYZQDW = "年";
            li.find("span[name=fwbmc]").html(item.fwbmc);
            li.find("span[name=JG]").html(item.FY);
            page_xzfwtc.setFwnrInfo(li, item.fwnrs);
            li.find("span[name=QYZQ]").html(item.QYZQ);
            li.find("span[name=QYZQDW]").html(item.QYZQDW);
            li.data(item);
            li.find("input").attr("onclick","checkForbid('"+i+"')");
            return li;
        }

        function setFwnrInfo(li, fwnrs) {
            if (!fwnrs)return;
            var container = li.find(".fwnrContainer");
            fwnrs = fwnrs.split("|");
            for (var i in fwnrs) {
                var span = $("<span>");
                var ind = parseInt(i) + 1;
                span.append(ind).append(".").append(fwnrs[i]).append("<br>");
                container.append(span);
            }
        }

        var cfg_def = {
            initView: initView,
            initData: initData,
            validate: validate,
            queryTcxx: queryTcxx,
            queryTcxxHandler: queryTcxxHandler,
            setItemInfo: setItemInfo,
            setFwnrInfo: setFwnrInfo,
        }

        page_xzfwtc.init = function(cfg){
            $.extend(page_xzfwtc, cfg_def, cfg);
            page_xzfwtc.initView();
            page_xzfwtc.initData();

        }

        return page_xzfwtc;
    })(jQuery, {});
    

</script>

</html>














